package edu.njust.Service.commodity.impl;

import edu.njust.Service.commodity.CommodityService;
import edu.njust.dao.CommodityMapper;
import edu.njust.domain.Commodity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommodityServiceImpl implements CommodityService {

    @Autowired
    private CommodityMapper commodityMapper;

    @Override
    public boolean deleteCommodity(int id) {
        int res = commodityMapper.deleteById(id);
        return res>0;
    }

    @Override
    public boolean insertCommodity(Commodity commodity) {
        int res = commodityMapper.insertCommodity(commodity);
        return res>0;
    }

    @Override
    public Commodity selectById(int id) {
        Commodity commodity= commodityMapper.selectById(id);
        return commodity;

    }

    @Override
    public boolean updateById(Commodity commodity) {
        return commodityMapper.updateById(commodity)>0;
    }

    @Override
    public List<Commodity> pageSelect(String commodityName, int commodityTypeID, int start, int pageSize) {
        List<Commodity> commodities = commodityMapper.pageSelect(commodityName,commodityTypeID,start,pageSize);
        return commodities;
    }

    @Override
    public int countSelect(String commodityName, int commodityTypeID) {
        return commodityMapper.countSelect(commodityName,commodityTypeID);
    }

    @Override
    public boolean selectYZ(String commodityName) {
        return commodityMapper.selectYZ(commodityName)>0;
    }

}
